// my-order-detail-un.js 
const tool = require('../../utils/util.js')
const scan = require('../../utils/scanCode')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        merchant_id: 0,
        infoId: 0,
        menuInfo: {}
    },
    deleteProduct: function () {

    },
    doScanAction: function (obj) {

        let objectToString = tool.objectToString(obj);
        getApp().http.request({
            url: '/api/v2/seat/scan?' + objectToString,
            success: function (httpRes) {
                var reponse = httpRes.data;
                if (reponse.code == 200 && reponse.data['order_seat_sn']) {
                    scan.saveScanQrcodeResult(
                        reponse.data['order_seat_sn'],reponse.data['mid'],objectToString,reponse.data['id']
                    )
                    let newVar = {url: "/pages/eating/eating"};
                    console.log(newVar)
                    wx.switchTab(newVar)
                }
            }
        })
    },
    doScan: function () {
        var that = this
        wx.scanCode({
            success: function (res) {
                wx.showToast({
                    title: '扫码成功',
                    icon: 'success',
                    duration: 2000,
                    complete: function () {
                        var obj = tool.parseQueryString(res.path)
                        that.doScanAction(obj)
                    }
                })
            }
        })
    },
    closeOrder: function (event) {
        var id = event.currentTarget.dataset.id
        getApp().http.request({
            url: "/api/v1/user_product/clear?merchant_id=" + this.data.merchant_id,
            success: function (res) {
                if (res.data.code == 200) {
                    var msg = '关闭成功';
                } else {
                    var msg = '关闭失败';
                }
                wx.showToast({
                    title: msg,
                    icon: 'success',
                    duration: 2000,
                    complete: function () {
                        wx.navigateBack({
                            delta: 1
                        })
                    }
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.showLoading({
            title: '加载中',
        })
        setTimeout(function () {
            wx.hideLoading()
        }, 1000)

        var that = this;
        if (options['id']) {
            this.data.merchant_id = options['id']
            this.data.infoId = options['infoId']
            getApp().http.request({
                url: "/api/v1/user_product/detail?merchant_id=" +  this.data.merchant_id,
                success: function (res) {
                    var reponse = res.data;
                    var orderInfo = reponse.data;
                    that.setData({
                        menuInfo: orderInfo
                    });
                }
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },


})